; -*- mode: lisp; -*-

;
; approximation of the Fujitsu Hoap-2 robot
;

(RSG 0 1)
( 
    ;
    ; define constants for the robot parts
    ;

    ; feet
    (def $FootLength 0.6)
    (def $FootWidth 0.956)
    (def $FootHeight 0.095)
    (def $FootMass 0.1)

    ; static box at the ankles
    (def $AnkleBoxLength 0.355)
    (def $AnkleBoxWidth 0.143)
    (def $AnkleBoxHeight 0.476)

    ; shanks
    (def $ShankLength 0.56)
    (def $ShankWidth 0.56)
    (def $ShankHeight 0.964)
    (def $ShankMass 0.25)

    ; thighs
    (def $ThighLength 0.56)
    (def $ThighWidth 0.56)
    (def $ThighHeight 1.3)
    (def $ThighMass 0.25)

    ; hips
    (def $HipLength 0.273)
    (def $HipWidth 0.273)
    (def $HipHeight 0.2)
    (def $HipMass 0.1)

    ; hand1
    (def $HandBox1Length 0.082)
    (def $HandBox1Width 0.272) 
    (def $HandBox1Height 0.57)

    ; hand2
    (def $HandBox2Length 0.242)
    (def $HandBox2Width 0.272)
    (def $HandBox2Height 0.164)

    ; hand3
    (def $HandBox3Length 0.074)
    (def $HandBox3Width 0.272)
    (def $HandBox3Height 0.2)

    ; lower arms
    (def $LowerarmLength 0.445)
    (def $LowerarmWidth 0.316)
    (def $LowerarmHeight 0.6)
    (def $LowerarmMass 0.2)

    ; elbows
    (def $ElbowDirection 1)
    (def $ElbowRadius 0.134)
    (def $ElbowLength 0.3)

    ; upper arms
    (def $UpperarmLength 0.445)
    (def $UpperarmWidth 0.398)
    (def $UpperarmHeight 0.506)
    (def $UpperarmMass 0.2)

    ; shoulders
    (def $ShoulderLength 0.445)
    (def $ShoulderWidth 1.017)
    (def $ShoulderHeight 0.536)
    (def $ShoulderMass 0.5) 

    ; head
    (def $HeadRadius 0.39)
    (def $HeadMass 0.3)

    ; neck
    (def $NeckLength 0.2)
    (def $NeckWidth 0.2)
    (def $NeckHeight 0.4)
    (def $NeckMass 0.1)

    ; torso1
    (def $TorsoBox1Length 1.37)
    (def $TorsoBox1Width 0.96)
    (def $TorsoBox1Height 1.41)
    (def $TorsoBox1Mass 1.8)

    ; torso2
    (def $TorsoBox2Length 1.37)
    (def $TorsoBox2Width 0.54)
    (def $TorsoBox2Height 1.81)
    (def $TorsoBox2Mass 1.8)

    (def $TorsoCylinderDirection 1)   ; oriented along x-axis
    (def $TorsoCylinderRadius 0.1)
    (def $TorsoCylinderLength 0.3)

    ;
    ; assemble the robot
    ;

    ; torso position (absolute)
    (def $TorsoPosX 0)
    (def $TorsoPosY -2)
    (def $TorsoPosZ 3.5)

    ; calculate offset of the battery pack
    (def $offsetTorsoBox2X 0.0)
    (def $offsetTorsoBox2Y (eval -1 * (eval (eval $TorsoBox1Width / 2.0) + (eval $TorsoBox2Width / 2.0))))
    (def $offsetTorsoBox2Z (eval -1 * (eval (eval $TorsoBox1Height / 2.0) - (eval $TorsoBox2Height / 2.0))))

    ; calculate offset for the left shoulder cylinder
    (def $offsetLeftShoulderCylX (eval -1 * (eval $TorsoBox1Length / 2.0)))
    (def $offsetLeftShoulderCylY 0.0)
    (def $offsetLeftShoulderCylZ (eval (eval $TorsoBox1Height / 2.0) - (eval $ShoulderHeight / 2.0)))
 
    ; calculate offset for the right shoulder cylinder
    (def $offsetRightShoulderCylX (eval $TorsoBox1Length / 2.0))
    (def $offsetRightShoulderCylY 0.0)
    (def $offsetRightShoulderCylZ (eval (eval $TorsoBox1Height / 2.0) - (eval $ShoulderHeight / 2.0)))

    ; create the torso
    (nd AgentAspect
        (setName body)
        (setLocalPos $TorsoPosX $TorsoPosY $TorsoPosZ)
        (importScene rsg/boxspheres/box.rsg $TorsoBox1Length $TorsoBox1Width $TorsoBox1Height $TorsoBox1Mass matGrey)

	; install a node holding agent state data
        (nd AgentState
	     (setName AgentState)
	)

	; static cylinders for the shoulders
	(nd Transform
	     (setLocalPos $offsetLeftShoulderCylX $offsetLeftShoulderCylY $offsetLeftShoulderCylZ)
	     (setLocalRotation 0 90 0)
	     (nd Capsule
		   (setMaterial matGrey)
		   (setParams $TorsoCylinderRadius $TorsoCylinderLength)
	     )
	)
	
	(nd Transform
	     (setLocalPos $offsetRightShoulderCylX $offsetRightShoulderCylY $offsetRightShoulderCylZ)
	     (setLocalRotation 0 90 0)
	     (nd Capsule
		   (setMaterial matGrey)
		   (setParams $TorsoCylinderRadius $TorsoCylinderLength)
	     )
	)
    )
	
    ;;; DEBUG
    ;(nd FixedJoint
	;  (attach ../body/boxBody 0) ; attach to the static environment
	;  (setFixed)
    ;)
    
    ; add battery backpack
    (nd Transform
	(setName battery)
	(setLocalPos (eval $TorsoPosX + $offsetTorsoBox2X) (eval $TorsoPosY + $offsetTorsoBox2Y + 0.01) (eval $TorsoPosZ + $offsetTorsoBox2Z))
	(importScene rsg/boxspheres/box.rsg $TorsoBox2Length $TorsoBox2Width $TorsoBox2Height $TorsoBox2Mass matGrey)

	; +++
	; THIS IS A HACK SINCE WE DON'T HAVE COMPOUND OBJECTS YET !
	; +++

	; install hinge joint to connect to the torso
        (nd HingeJoint
            (attach ../boxBody ../../body/boxBody)
            (setAnchor 0.0 0.0 0.0)   
            (setAxis 2) ; move around z-axis
	    (setLowStopDeg 0 0.01)
	    (setHighStopDeg 0 0.01)
	)
    )

    ;;; -------------------------------------
    ;;; HEAD
    ;;; -------------------------------------
    
    ; attach neck
    (nd Transform
        (setName neck)
        (setLocalPos $TorsoPosX (eval $TorsoPosY - 0.1) (eval $TorsoPosZ + (eval $TorsoBox1Height / 2.0) + (eval $NeckHeight / 2.0)))
        (importScene rsg/boxspheres/box.rsg $NeckLength $NeckWidth $NeckHeight $NeckMass matGrey)

        ; install hinge joint to connect to the torso
        (nd HingeJoint
            (attach ../boxBody ../../body/boxBody)
            (setAnchor $TorsoPosX (eval $TorsoPosY - 0.1) (eval $TorsoPosZ + (eval $TorsoBox1Height / 2.0)))   
            (setAxis 2) ; move around z-axis
            
            ; enable the joint motors
            (setMaxMotorForce 0 100)

            ; install a perceptor
            (nd HingePerceptor
                (setName head_joint_2)
            )

            ; install an effector to control the joint motors
            (nd HingeEffector
                (setName head_eff_2)
            )
        )
    )

    ; attach head
    (nd Transform
        (setName head)
        (setLocalPos $TorsoPosX 
		     (eval $TorsoPosY + 0.05) 
		     (eval $TorsoPosZ + (eval $TorsoBox1Height / 2.0) + (eval $NeckHeight / 2.0) + (eval $HeadRadius / 2.0)))
        (importScene rsg/boxspheres/sphere.rsg $HeadRadius $HeadMass matLightBlue)
	(nd VisionPerceptor
	      (setSenseMyPos false)
	      (setStaticSenseAxis false)
	      (addNoise false)
        )
	(nd TimePerceptor)

        ; install hinge joint to connect to the neck
        (nd HingeJoint
            (attach ../sphereBody ../../neck/boxBody)
            (setAnchor $TorsoPosX (eval $TorsoPosY - 0.1) (eval $TorsoPosZ + (eval $TorsoBox1Height / 2.0) + $NeckHeight))
            (setAxis 0) ; move around the x-axis

            ; enable the joint motor
            (setMaxMotorForce 0 100)

            ; install a perceptor
            (nd HingePerceptor
                (setName head_joint_1)
            )

            ; install an effector to control the joint motor
            (nd HingeEffector
                (setName head_eff_1)
            )
        )
    )

    ;;; -------------------------------------
    ;;; ARMS
    ;;; -------------------------------------

    (def $LeftShoulderPosX (eval $TorsoPosX - 
				    (eval $TorsoBox1Length / 2.0) - 
				    (eval $ShoulderLength / 2.0) - 
				    (eval $TorsoCylinderLength / 2.0)
			       )
    )
    (def $LeftShoulderPosY $TorsoPosY)
    (def $LeftShoulderPosZ (eval $TorsoPosZ + 
				    (eval $TorsoBox1Height / 2.0) -
				    (eval $ShoulderHeight / 2.0)
			       )
    )

    (def $RightShoulderPosX (eval $TorsoPosX +
				    (eval $TorsoBox1Length / 2.0) + 
				    (eval $ShoulderLength / 2.0) + 
				    (eval $TorsoCylinderLength / 2.0)
			       )
    )
    (def $RightShoulderPosY $TorsoPosY)
    (def $RightShoulderPosZ $LeftShoulderPosZ)
 
    ; left shoulder
    (nd Transform
        (setName leftshoulder)
        (setLocalPos $LeftShoulderPosX $LeftShoulderPosY $LeftShoulderPosZ)
        (importScene rsg/boxspheres/box.rsg $ShoulderLength $ShoulderWidth $ShoulderHeight $ShoulderMass matGrey)

        ; install universal joint to connect to the torso
        (nd UniversalJoint
            (attach ../boxBody ../../body/boxBody)
            (setAnchor 0.0 0.0 0.0)   
            (setAxis1 1.0 0.0 0.0) ; move around the x-axis
            (setAxis2 0.0 1.0 0.0) ; move around the y-axis

            ; enable the joint motors
            (setMaxMotorForce 0 100)
            (setMaxMotorForce 1 100)           

            ; install a perceptor
            (nd UniversalJointPerceptor
                (setName larm_joint_1_2)
            )

            ; install an effector to control the joint motors
            (nd UniversalJointEffector
                (setName larm_eff_1_2)
            )
        )
    )

    ; right shoulder
    (nd Transform
        (setName rightshoulder)
        (setLocalPos $RightShoulderPosX $RightShoulderPosY $RightShoulderPosZ)
        (importScene rsg/boxspheres/box.rsg $ShoulderLength $ShoulderWidth $ShoulderHeight $ShoulderMass matGrey)
        (setLocalRotation 0 0 180)

            ; install universal joint to connect to the torso
	    (nd UniversalJoint		
                (attach ../boxBody ../../body/boxBody)
		(setAnchor 0.0 0.0 0.0)  
		(setAxis1 1.0 0.0 0.0) ; move around the x-axis
		(setAxis2 0.0 1.0 0.0) ; move around the y-axis

                ; enable the joint motors
		(setMaxMotorForce 0 100)
		(setMaxMotorForce 1 100)           

                ; install a perceptor
                (nd UniversalJointPerceptor
                    (setName rarm_joint_1_2)
		)

                ; install an effector to control the joint motors
                (nd UniversalJointEffector
                    (setName rarm_eff_1_2)
                )
            )
    )

    (def $LeftUpperArmPosX $LeftShoulderPosX)
    (def $LeftUpperArmPosY (eval $LeftShoulderPosY + (eval $UpperarmWidth / 2.0)))
    (def $LeftUpperArmPosZ (eval $LeftShoulderPosZ - (eval $ShoulderHeight / 2.0) - (eval $UpperarmHeight / 2.0)))

    (def $RightUpperArmPosX $RightShoulderPosX)
    (def $RightUpperArmPosY (eval $RightShoulderPosY + (eval $UpperarmWidth / 2.0)))
    (def $RightUpperArmPosZ (eval $RightShoulderPosZ - (eval $ShoulderHeight / 2.0) - (eval $UpperarmHeight / 2.0)))
    
    ; left upper arm
    (nd Transform
        (setName leftupperarm)
        (setLocalPos $LeftUpperArmPosX $LeftUpperArmPosY $LeftUpperArmPosZ)
        (importScene rsg/boxspheres/box.rsg $UpperarmLength $UpperarmWidth $UpperarmHeight $UpperarmMass matGrey)

        ; install hinge joint to connect to the shoulder
        (nd HingeJoint
            (attach ../boxBody ../../leftshoulder/boxBody)
            (setAnchor 0.0 0.0 (eval $UpperarmHeight / 2.0))   
            (setAxis 2) ; move around z-axis
            
            ; enable the joint motors
            (setMaxMotorForce 0 100)

            ; install a perceptor
            (nd HingePerceptor
                (setName larm_joint_3)
            )

            ; install an effector to control the joint motors
            (nd HingeEffector
                (setName larm_eff_3)
            )
        )

	; static cylinder for the elbow
	(nd Transform
	     (setLocalPos 0 0 (eval -1 * (eval (eval $UpperarmHeight / 2.0) + (eval $ElbowRadius / 2.0))))
	     (setLocalRotation 0 90 0)
	     (nd Capsule
		   (setMaterial matGrey)
		   (setParams $ElbowRadius $ElbowLength)
	     )
	)
    )

    ; right upper arm
    (nd Transform
        (setName rightupperarm)
        (setLocalPos $RightUpperArmPosX $RightUpperArmPosY $RightUpperArmPosZ)
	(importScene rsg/boxspheres/box.rsg $UpperarmLength $UpperarmWidth $UpperarmHeight $UpperarmMass matGrey)
	
        ; install hinge joint to connect to the shoulder
        (nd HingeJoint
            (attach ../boxBody ../../rightshoulder/boxBody)
            (setAnchor 0 0 (eval $UpperarmHeight / 2.0))   
            (setAxis 2) ; move around z-axis
            
            ; enable the joint motors
            (setMaxMotorForce 0 100)

            ; install a perceptor
            (nd HingePerceptor
                (setName rarm_joint_3)
            )

            ; install an effector to control the joint motors
            (nd HingeEffector
                (setName rarm_eff_3)
            )
        )

	; static cylinder for the elbow
	(nd Transform
	     (setLocalPos 0 0 (eval -1 * (eval (eval $UpperarmHeight / 2.0) + (eval $ElbowRadius / 2.0))))
	     (setLocalRotation 0 90 0)
	     (nd Capsule
		   (setMaterial matGrey)
		   (setParams $ElbowRadius $ElbowLength)
	     )
	)
    )

    (def $LeftLowerArmPosX $LeftUpperArmPosX)
    (def $LeftLowerArmPosY $LeftUpperArmPosY)
    (def $LeftLowerArmPosZ (eval $LeftUpperArmPosZ -
				    (eval $UpperarmHeight / 2.0) -
				    $ElbowRadius -
				    (eval $LowerarmHeight / 2.0)
			       )
     )

    (def $RightLowerArmPosX $RightUpperArmPosX)
    (def $RightLowerArmPosY $RightUpperArmPosY)
    (def $RightLowerArmPosZ (eval $RightUpperArmPosZ -
				    (eval $UpperarmHeight / 2.0) -
				    $ElbowRadius -
				    (eval $LowerarmHeight / 2.0)
			       )
     )

    ; left lower arm
    (nd Transform
        (setName leftlowerarm)
        (setLocalPos $LeftLowerArmPosX $LeftLowerArmPosY $LeftLowerArmPosZ)
        (importScene rsg/boxspheres/box.rsg $LowerarmLength $LowerarmWidth $LowerarmHeight $LowerarmMass matGrey)

        ; install hinge joint to connect to the upper arm
        (nd HingeJoint
            (attach ../boxBody ../../leftupperarm/boxBody)
            (setAnchor 0 0 (eval $LowerarmHeight / 2.0))   
            (setAxis 0) ; move around x-axis
            
            ; enable the joint motors
            (setMaxMotorForce 0 100)

            ; install a perceptor
            (nd HingePerceptor
                (setName larm_joint_4)
            )

            ; install an effector to control the joint motors
            (nd HingeEffector
                (setName larm_eff_4)
            )
        )

	; static hand
	(nd Transform
	     (setLocalPos (eval -1 * (eval (eval $LowerarmLength / 2.0) - (eval $HandBox1Length / 2.0) - 0.06))
			  0.0
			  (eval -1 * (eval (eval $LowerarmHeight / 2.0) + (eval $HandBox1Height / 2.0)))
	      )
	     (nd Box
		   (setMaterial matGrey)
		   (setExtents $HandBox1Length $HandBox1Width $HandBox1Height)
	     )	     
        )
	
	(nd Transform
	     (setLocalPos (eval (eval $LowerarmLength / 2.0) - (eval $HandBox2Length / 2.0) - 0.06)
			  0.0
			  (eval -1 * (eval (eval $LowerarmHeight / 2.0) + (eval $HandBox2Height / 2.0)))
	      )
	     (nd Box
		   (setMaterial matGrey)
		   (setExtents $HandBox2Length $HandBox2Width $HandBox2Height)
	     )
	)

	(nd Transform
	     (setLocalPos (eval (eval $LowerarmLength / 2.0) - (eval $HandBox3Length / 2.0) - 0.06)
			  0.0
			  (eval -1 * (eval (eval $LowerarmHeight / 2.0) + $HandBox2Height + (eval $HandBox3Height / 2.0)))
	      )
	     (nd Box
		   (setMaterial matGrey)
		   (setExtents $HandBox3Length $HandBox3Width $HandBox3Width)
	     )
	)
    )

    ; right lower arm
    (nd Transform
        (setName rightlowerarm)
        (setLocalPos $RightLowerArmPosX $RightLowerArmPosY $RightLowerArmPosZ)
	;(setLocalRotation 0 0 180)
        (importScene rsg/boxspheres/box.rsg $LowerarmLength $LowerarmWidth $LowerarmHeight $LowerarmMass matGrey)

        ; install hinge joint to connect to the upper arm
        (nd HingeJoint
            (attach ../boxBody ../../rightupperarm/boxBody)
            (setAnchor 0 0 (eval $LowerarmHeight / 2.0))   
            (setAxis 0) ; move around x-axis
            
            ; enable the joint motors
            (setMaxMotorForce 0 100)

            ; install a perceptor
            (nd HingePerceptor
                (setName rarm_joint_4)
            )

            ; install an effector to control the joint motors
            (nd HingeEffector
                (setName rarm_eff_4)
            )
        )

	; static hand
	(nd Transform
	      (setLocalRotation 0 0 180)
	      
	      (nd Transform
		    (setLocalPos (eval -1 * (eval (eval $LowerarmLength / 2.0) - (eval $HandBox1Length / 2.0) - 0.06))
				 0.0
				 (eval -1 * (eval (eval $LowerarmHeight / 2.0) + (eval $HandBox1Height / 2.0)))
				 )
		    (nd Box
			  (setMaterial matGrey)
			  (setExtents $HandBox1Length $HandBox1Width $HandBox1Height)
			  )	     
		    )
	      
	      (nd Transform
		    (setLocalPos (eval (eval $LowerarmLength / 2.0) - (eval $HandBox2Length / 2.0) - 0.06)
				 0.0
				 (eval -1 * (eval (eval $LowerarmHeight / 2.0) + (eval $HandBox2Height / 2.0)))
				 )
		    (nd Box
			  (setMaterial matGrey)
			  (setExtents $HandBox2Length $HandBox2Width $HandBox2Height)
			  )
		    )
	      
	      (nd Transform
		    (setLocalPos (eval (eval $LowerarmLength / 2.0) - (eval $HandBox3Length / 2.0) - 0.06)
				 0.0
				 (eval -1 * (eval (eval $LowerarmHeight / 2.0) + $HandBox2Height + (eval $HandBox3Height / 2.0)))
				 )
		    (nd Box
			  (setMaterial matGrey)
			  (setExtents $HandBox3Length $HandBox3Width $HandBox3Width)
			  )
		    )
	)
    )

    ;;; -------------------------------------
    ;;; LEGS
    ;;; -------------------------------------
    
    (def $LeftHipPosX (eval $TorsoPosX - (eval $TorsoBox1Length / 4.0) - 0.06))
    (def $LeftHipPosY $TorsoPosY)
    (def $LeftHipPosZ (eval $TorsoPosZ - (eval $TorsoBox1Height / 2.0) - (eval $HipHeight / 2.0)))

    (def $RightHipPosX (eval $TorsoPosX + (eval $TorsoBox1Length / 4.0) + 0.06))
    (def $RightHipPosY $TorsoPosY)
    (def $RightHipPosZ (eval $TorsoPosZ - (eval $TorsoBox1Height / 2.0) - (eval $HipHeight / 2.0)))


    ; left hip
    (nd Transform
        (setName lefthip)
        (setLocalPos $LeftHipPosX $LeftHipPosY $LeftHipPosZ)
        (importScene rsg/boxspheres/box.rsg $HipLength $HipWidth $HipHeight $HipMass matGrey)

        ; install hinge joint to connect to the torso
        (nd HingeJoint
            (attach ../boxBody ../../body/boxBody)
            (setAnchor 0 0 (eval $HipHeight / 2.0))   
            (setAxis 2) ; move around z-axis
            
            ; enable the joint motors
            (setMaxMotorForce 0 100)

            ; install a perceptor
            (nd HingePerceptor
                (setName lleg_joint_1)
            )

            ; install an effector to control the joint motors
            (nd HingeEffector
                (setName lleg_eff_1)
            )
        )
    )

    ; right hip
    (nd Transform
        (setName righthip)
        (setLocalPos $RightHipPosX $RightHipPosY $RightHipPosZ)
        (importScene rsg/boxspheres/box.rsg $HipLength $HipWidth $HipHeight $HipMass matGrey)

        ; install hinge joint to connect to the torso
        (nd HingeJoint
            (attach ../boxBody ../../body/boxBody)
            (setAnchor 0 0 (eval $HipHeight / 2.0))   
            (setAxis 2) ; move around z-axis
            
            ; enable the joint motors
            (setMaxMotorForce 0 100)

            ; install a perceptor
            (nd HingePerceptor
                (setName rleg_joint_1)
            )

            ; install an effector to control the joint motors
            (nd HingeEffector
                (setName rleg_eff_1)
            )
        )
    )

    (def $LeftThighPosX $LeftHipPosX)
    (def $LeftThighPosY $LeftHipPosY)
    (def $LeftThighPosZ (eval $LeftHipPosZ - (eval $HipHeight / 2.0) - (eval $ThighHeight / 2.0)))

    (def $RightThighPosX $RightHipPosX)
    (def $RightThighPosY $RightHipPosY)
    (def $RightThighPosZ (eval $RightHipPosZ - (eval $HipHeight / 2.0) - (eval $ThighHeight / 2.0)))

    ; left thigh
    (nd Transform
        (setName leftthigh)
        (setLocalPos $LeftThighPosX $LeftThighPosY $LeftThighPosZ)
        (importScene rsg/boxspheres/box.rsg $ThighLength $ThighWidth $ThighHeight $ThighMass matGrey)

        ; install hinge joint to connect to the torso
        (nd UniversalJoint
            (attach ../boxBody ../../lefthip/boxBody)
            (setAnchor 0.0 0.0 (eval $ThighHeight / 2.0))   
            (setAxis1 1.0 0.0 0.0) ; move around the x-axis
            (setAxis2 0.0 1.0 0.0) ; move around the y-axis

            ; enable the joint motors
            (setMaxMotorForce 0 100)
            (setMaxMotorForce 1 100)           

            ; install a perceptor
            (nd UniversalJointPerceptor
                (setName lleg_joint_2_3)
            )

            ; install an effector to control the joint motors
            (nd UniversalJointEffector
                (setName lleg_eff_2_3)
            )
        )
    )

    ; right thigh
    (nd Transform
        (setName rightthigh)
        (setLocalPos $RightThighPosX $RightThighPosY $RightThighPosZ)
        (importScene rsg/boxspheres/box.rsg $ThighLength $ThighWidth $ThighHeight $ThighMass matGrey)

        ; install hinge joint to connect to the torso
        (nd UniversalJoint
            (attach ../boxBody ../../righthip/boxBody)
            (setAnchor 0.0 0.0 (eval $ThighHeight / 2.0))   
            (setAxis1 1.0 0.0 0.0) ; move around the x-axis
            (setAxis2 0.0 1.0 0.0) ; move around the y-axis

            ; enable the joint motors
            (setMaxMotorForce 0 100)
            (setMaxMotorForce 1 100)           

            ; install a perceptor
            (nd UniversalJointPerceptor
                (setName rleg_joint_2_3)
            )

            ; install an effector to control the joint motors
            (nd UniversalJointEffector
                (setName rleg_eff_2_3)
            )
        )
    )

    (def $LeftShankPosX $LeftThighPosX)
    (def $LeftShankPosY $LeftThighPosY)
    (def $LeftShankPosZ (eval $LeftThighPosZ - (eval $ThighHeight / 2.0) - (eval $ShankHeight / 2.0) - 0.05))

    (def $RightShankPosX $RightThighPosX)
    (def $RightShankPosY $RightThighPosY)
    (def $RightShankPosZ (eval $RightThighPosZ - (eval $ThighHeight / 2.0) - (eval $ShankHeight / 2.0) - 0.05))

    ; left shank
    (nd Transform
        (setName leftshank)
        (setLocalPos $LeftShankPosX $LeftShankPosY $LeftShankPosZ)
        (importScene rsg/boxspheres/box.rsg $ShankLength $ShankWidth $ShankHeight $ShankMass matGrey)

        ; install hinge joint to connect to the thigh
        (nd HingeJoint
            (attach ../boxBody ../../leftthigh/boxBody)
            (setAnchor 0.0 0.0 (eval $ShankHeight / 2.0))   
            (setAxis 0) ; move around x-axis
            
            ; enable the joint motors
            (setMaxMotorForce 0 100)

            ; install a perceptor
            (nd HingePerceptor
                (setName lleg_joint_4)
            )

            ; install an effector to control the joint motors
            (nd HingeEffector
                (setName lleg_eff_4)
            )
        )
    )

    ; right shank
    (nd Transform
        (setName rightshank)
        (setLocalPos $RightShankPosX $RightShankPosY $RightShankPosZ)
        (importScene rsg/boxspheres/box.rsg $ShankLength $ShankWidth $ShankHeight $ShankMass matGrey)

        ; install hinge joint to connect to the thigh
        (nd HingeJoint
            (attach ../boxBody ../../rightthigh/boxBody)
            (setAnchor 0.0 0.0 (eval $ShankHeight / 2.0))
            (setAxis 0) ; move around x-axis
            
            ; enable the joint motors
            (setMaxMotorForce 0 100)

            ; install a perceptor
            (nd HingePerceptor
                (setName rleg_joint_4)
            )

            ; install an effector to control the joint motors
            (nd HingeEffector
                (setName rleg_eff_4)
            )
        )
    )

    ; left foot
    (nd Transform
        (setName leftfoot)
        (setLocalPos $LeftShankPosX 
		     $LeftShankPosY
		     (eval $LeftShankPosZ - (eval $ShankHeight / 2.0) - (eval $FootHeight / 2.0) - 0.05)
	 )
        (importScene rsg/boxspheres/box.rsg $FootLength $FootWidth $FootHeight $FootMass matGrey)

        ; install hinge joint to connect to the shank
        (nd UniversalJoint
            (attach ../boxBody ../../leftshank/boxBody)
            (setAnchor 0.0 0.0 (eval $FootHeight / 2.0))   
            (setAxis1 1.0 0.0 0.0) ; move around the x-axis
            (setAxis2 0.0 1.0 0.0) ; move around the y-axis

            ; enable the joint motors
           (setMaxMotorForce 0 100)
           (setMaxMotorForce 1 100)           

            ; install a perceptor
          (nd UniversalJointPerceptor
              (setName lleg_joint_5_6)
         )

            ; install an effector to control the joint motors
            (nd UniversalJointEffector
                (setName lleg_eff_5_6)
            )
        )

	; static box at the back of the foot
	(nd Transform
	     (setLocalPos 0.0
			  (eval -1 * (eval (eval $FootWidth / 2.0) - (eval $AnkleBoxWidth / 2.0)))
			  (eval (eval $FootHeight / 2.0) + (eval $AnkleBoxHeight / 2.0))
	      )
	     (nd Box
		   (setMaterial matGrey)
		   (setExtents $AnkleBoxLength $AnkleBoxWidth $AnkleBoxHeight)
	     )
	)
    )

    ; right foot
    (nd Transform
        (setName rightfoot)
        (setLocalPos $RightShankPosX 
		     $RightShankPosY
		     (eval $RightShankPosZ - (eval $ShankHeight / 2.0) - (eval $FootHeight / 2.0) - 0.05)
	 )
        (importScene rsg/boxspheres/box.rsg $FootLength $FootWidth $FootHeight $FootMass matGrey)

        ; install hinge joint to connect to the shank
        (nd UniversalJoint
            (attach ../boxBody ../../rightshank/boxBody)
            (setAnchor 0.0 0.0 (eval $FootHeight / 2.0))   
            (setAxis1 1.0 0.0 0.0) ; move around the x-axis
            (setAxis2 0.0 1.0 0.0) ; move around the y-axis

            ; enable the joint motors
            (setMaxMotorForce 0 100)
            (setMaxMotorForce 1 100)           

            ; install a perceptor
            (nd UniversalJointPerceptor
                (setName rleg_joint_5_6)
            )

            ; install an effector to control the joint motors
            (nd UniversalJointEffector
                (setName rleg_eff_5_6)
            )
        )

	; static box at the back of the foot
	(nd Transform
	     (setLocalPos 0.0
			  (eval -1 * (eval (eval $FootWidth / 2.0) - (eval $AnkleBoxWidth / 2.0)))
			  (eval (eval $FootHeight / 2.0) + (eval $AnkleBoxHeight / 2.0))
	      )
	     (nd Box
		   (setMaterial matGrey)
		   (setExtents $AnkleBoxLength $AnkleBoxWidth $AnkleBoxHeight)
	     )
	)
    )

) ; EOF
